package com.fourth.controller.api;

import com.fourth.service.UbCollectionService;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Goods;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.ma
 * @since 2023/3/2 17:09
 **/
@RestController
@RequestMapping("/detail/commodity")
@Api("商品或店铺收藏关注操作接口")
public class UbApiCollectionController {

    @Resource
    private UbCollectionService ubCollectionService;

    @RequestMapping("changeGuanzhu/{bid}/{status}")
    @ApiOperation("关注或取关店铺")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bid", value = "店铺id", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "0取关，1关注", dataType = "Comment")
    })
    public Result changeGuanzhu(@PathVariable("bid") String bid,@PathVariable("status") Integer status){
        int row = ubCollectionService.changeStatus(bid,status,0);
        if (row > 0){
            return new Result(2000,"更新状态成功",null);
        }
        return new Result(5000,"更新状态失败",null);
    }

    @RequestMapping("isCollectionBusiness/{bid}")
    @ApiOperation("判断是否关注店铺，返回0表示已关注，返回1表示未关注")
    @ApiImplicitParam(name = "bid", value = "店铺id", dataType = "String")
    public Result isCollectionBusiness(@PathVariable String bid){
        int row = ubCollectionService.isCollectionBusiness(bid,0);

        return new Result(2000,"收藏状态",row);
    }

    @RequestMapping("changeCollectionStatus/{id}/{status}")
    @ApiOperation("收藏或取消收藏商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "0取消收藏，1收藏", dataType = "Comment")
    })
    public Result changeCollectionStatus(@PathVariable("id") String id,@PathVariable("status") Integer status){
        int row = ubCollectionService.changeStatus(id,status,1);
        if (row > 0){
            return new Result(2000,"更新状态成功",null);
        }
        return new Result(5000,"更新状态失败",null);
    }

    @RequestMapping("isGoodsCollection/{id}")
    @ApiOperation("判断是否收藏该商品，返回0表示已收藏，返回1表示未收藏")
    @ApiImplicitParam(name = "id", value = "商品id", dataType = "String")
    public Result isGoodsCollection(@PathVariable("id") String id){
        int row = ubCollectionService.isCollectionBusiness(id,1);

        return new Result(2000,"收藏状态",row);
    }

    @RequestMapping("findGid")
    @ApiOperation("获取登录用户收藏的商品")
    public Result<List<Goods>> findGid(){
        List<Goods> goodsList = ubCollectionService.findCollection(1);
        return new Result(2000,"查询成功",goodsList);
    }

    @RequestMapping("findBid")
    @ApiOperation("获取登录用户关注的店铺")
    public Result<BusinessInfo> findBid(){
        List<BusinessInfo> businessInfos = ubCollectionService.findCollection(0);
        return new Result(2000,"查询成功",businessInfos);
    }

    @RequestMapping("deleteBid")
    @ApiOperation("取消店铺关注")
    @ApiImplicitParam(name = "bid", value = "店铺id", dataType = "String")
    public Result deleteBid(String bid){
        int row = ubCollectionService.changeStatus(bid,1,0);
        return new Result(2000,"取消关注",row);
    }

    @RequestMapping("deleteGid")
    @ApiOperation("取消商品收藏")
    @ApiImplicitParam(name = "goodsid", value = "商品id", dataType = "String")
    public Result deleteGid(String goodsid){
        int row = ubCollectionService.changeStatus(goodsid,1,1);
        return new Result(2000,"取消收藏",row);
    }

}
